package br.edu.infnet.repositorio;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.ejb.EJB;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.Query;

import br.edu.infnet.dao.ClienteDao;
import br.edu.infnet.model.Cliente;
@Stateless
@LocalBean
public class RepositorioCliente implements IRepositorio<Cliente> {
	@EJB
	private ClienteDao dao;
	
	public RepositorioCliente() {

	}
	
	@Override
	public void criar(Cliente entity) {
		
		dao.save(entity);
		
	}

	@Override
	public void remover(Cliente entity) {
		dao.delete(entity);
		
	}

	@Override
	public void atualizar(Cliente entity) {
		
		dao.update(entity);
		
	}

	@Override
	public Cliente consultarporID(int id) {
		
		Cliente result = dao.findById(id);
		
		return result;
	}

	@Override
	public List<Cliente> consultarTodos() {
		
		List<Cliente> clientes = dao.findAll(Cliente.getFindAll());
		
		return clientes;
	}
	
	public Cliente findByCPF(String cpf) {
		
		Cliente result;
		
		Query q = dao.getEm().createQuery("SELECT c FROM Cliente c where nuInscricao='" + cpf + "'");
		
		result = dao.OneResultQuery(q);
		
		return result;
		
	}

}
